<?php
/**
 * Created by PhpStorm.
 * User: ztos
 * Date: 2017/11/13
 * Time: 上午9:26
 */

namespace app\admin\controller;

use think\cache\driver\Redis;
use think\Model;

class RedisTest extends Model
{
    /**
     * redis 测试  redis 作为消息队列的使用
     */
    public function test(){
        $redis = new Redis();
        //name列表左侧添加数据
        $redis->handler()->lPush('name',"test1");
        //返回name列表的数据长度

        return $redis->handler()->lLen('name');
    }

    /**
     * 入消息队列
     */
    public function pushList(){
        $data = input('post.');
        $redis = new Redis();
        $length = $redis->handler()->lLen('list');
        if ($length <10){
            $insert = json_encode($data);
            $res = $redis->handler()->lPush('list',$insert);
        }else{
            return "服务器繁忙！";
        }
    }

    /**
     * 出消息队列
     */
    public function popList(){
        $redis = new Redis();
        $popjson = $redis->handler()->rPop('list');

        return $popjson;
    }







}